package lmscript.postscript.syntax;

import lmscript.postscript.syntax.stack.OperandStack;

public abstract class ControlOperator extends PSOperator {

	public static Class[] operators = new Class[] { Exec.class, If.class, IfElse.class, For.class,
			Repeat.class, Loop.class, Exit.class, Stop.class, Stopped.class, CountExecStack.class,
			ExecStack.class, Quit.class, Start.class };

	ControlOperator(String name) {
		super(name);
	}
}

class Exec extends ControlOperator {

	public Exec() {
		super("exec");
		operandTypes = new Class[] { PSObject.class };
	}

	@Override
	public boolean execute(OperandStack os) {
		os.getExecutionStack().pop();
		os.getExecutionStack().push(os.pop());
		return false;
	}
}

class If extends ControlOperator {

	public If() {
		super("if");
		operandTypes = new Class[] { PSBoolean.class, PSArray.class };
	}

	@Override
	public boolean execute(OperandStack os) {
		PSArray p = os.popArray();
		PSBoolean b = os.popBoolean();
		if (b.getValue()) {
			os.getExecutionStack().pop();
			os.getExecutionStack().push(p);
			return false;
		}
		return true;
	}
}

class IfElse extends ControlOperator {

	public IfElse() {
		super("ifelse");
	}

	@Override
	public boolean execute(OperandStack os) {
		return false;
	}
}

class For extends ControlOperator {

	public For() {
		super("for");
	}

	@Override
	public boolean execute(OperandStack os) {
		return false;
	}
}

class Repeat extends ControlOperator {

	public Repeat() {
		super("Repeat");
	}

	@Override
	public boolean execute(OperandStack os) {
		return false;
	}
}

class Loop extends ControlOperator {

	public Loop() {
		super("loop");
	}

	@Override
	public boolean execute(OperandStack os) {
		return false;
	}
}

class Exit extends ControlOperator {

	public Exit() {
		super("exit");
	}

	@Override
	public boolean execute(OperandStack os) {
		return false;
	}
}

class Stop extends ControlOperator {

	public Stop() {
		super("stop");
	}

	@Override
	public boolean execute(OperandStack os) {
		return false;
	}
}

class Stopped extends ControlOperator {

	public Stopped() {
		super("stopped");
	}

	@Override
	public boolean execute(OperandStack os) {
		return false;
	}
}

class CountExecStack extends ControlOperator {

	public CountExecStack() {
		super("countexecstack");
	}

	@Override
	public boolean execute(OperandStack os) {
		return false;
	}
}

class ExecStack extends ControlOperator {

	public ExecStack() {
		super("execstack");
	}

	@Override
	public boolean execute(OperandStack os) {
		return false;
	}
}

class Quit extends ControlOperator {

	public Quit() {
		super("quit");
	}

	@Override
	public boolean execute(OperandStack os) {
		return false;
	}
}

class Start extends ControlOperator {

	public Start() {
		super("start");
	}

	@Override
	public boolean execute(OperandStack os) {
		return false;
	}
}
